package com.frcdi.qms.web.controller.system;

import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.common.utils.poi.ExcelUtil;
import com.frcdi.qms.system.domain.SysDigitalSign;
import com.frcdi.qms.system.domain.vo.DigitalSignVO;
import com.frcdi.qms.system.service.ISysDigitalSignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 电子签名Controller
 *
 * @author cell
 * @date 2023-10-13
 */
@Api(tags = "电子签名")
@RestController
@RequestMapping("/system/sign")
public class SysDigitalSignController extends BaseController
{
    @Autowired
    private ISysDigitalSignService sysDigitalSignService;

    /**
     * 查询电子签名列表
     */
    @ApiOperation("查询电子签名列表")
    @PreAuthorize("@ss.hasPermi('system:sign:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDigitalSign sysDigitalSign)
    {
        startPage();
        List<SysDigitalSign> list = sysDigitalSignService.selectSysDigitalSignList(sysDigitalSign);
        return getDataTable(list);
    }

    /**
     * 导出电子签名列表
     */
    @ApiOperation("导出电子签名列表")
    @PreAuthorize("@ss.hasPermi('system:sign:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDigitalSign sysDigitalSign)
    {
        List<SysDigitalSign> list = sysDigitalSignService.selectSysDigitalSignList(sysDigitalSign);
        ExcelUtil<SysDigitalSign> util = new ExcelUtil<SysDigitalSign>(SysDigitalSign.class);
        util.exportExcel(response, list, "电子签名数据");
    }

    /**
     * 获取电子签名详细信息
     */
    @ApiOperation("获取电子签名详细信息")
    @PreAuthorize("@ss.hasPermi('system:sign:query')")
    @GetMapping(value = "/{signId}")
    public AjaxResult getInfo(@PathVariable("signId") Long signId)
    {
        return success(sysDigitalSignService.selectSysDigitalSignBySignId(signId));
    }

    /**
     * 新增电子签名
     */
    @ApiOperation("新增电子签名")
    @PreAuthorize("@ss.hasPermi('system:sign:add')")
    @PostMapping
    public AjaxResult add(@RequestBody DigitalSignVO sysDigitalSign)
    {
        return toAjax(sysDigitalSignService.insertSysDigitalSign(sysDigitalSign));
    }

}
